<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.value"
          clearable
          placeholder="输入搜索内容"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select
          v-model="query.type"
          clearable
          placeholder="类型"
          class="filter-item"
          style="width: 130px"
        >
          <el-option
            v-for="item in queryTypeOptions"
            :key="item.key"
            :label="item.display_name"
            :value="item.key"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="550px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
          <el-form-item label="舷号">
            <el-input v-model="form.shipNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="硬件">
            <el-input v-model="form.hardwareEnv" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="输入部件">
            <el-input v-model="form.inputUnit" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="视频总线">
            <el-input v-model="form.videoBus" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="会商桌">
            <el-input v-model="form.conferenceTable" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="软件架构">
            <el-input v-model="form.softStruct" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="操作系统">
            <el-input v-model="form.operatingSystem" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="系统版本">
            <el-input v-model="form.operatingVersion" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="构建基本平台">
            <el-input v-model="form.platBase" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="数据库">
            <el-select v-model="form.database" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.database_type"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="数据库版本">
            <el-input v-model="form.databaseVersion" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="数据库模式">
            <el-select v-model="form.databaseMode" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.database_mode"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="QT版本">
            <el-input v-model="form.qtVersion" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="开发工具">
            <el-input v-model="form.developmentTool" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="开始时间">
            <el-date-picker v-model="form.startTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="结束时间">
            <el-date-picker v-model="form.endTime" type="datetime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="30" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="ID" width="50" />
        <el-table-column v-if="columns.visible('shipNo')" prop="shipNo" label="舷号" />
        <el-table-column v-if="columns.visible('hardwareEnv')" prop="hardwareEnv" label="硬件" />
        <el-table-column v-if="columns.visible('inputUnit')" prop="inputUnit" label="输入部件" />
        <el-table-column v-if="columns.visible('videoBus')" prop="videoBus" label="视频总线" />
        <el-table-column
          v-if="columns.visible('conferenceTable')"
          prop="conferenceTable"
          label="会商桌"
        />
        <el-table-column v-if="columns.visible('softStruct')" prop="softStruct" label="软件架构" />
        <el-table-column
          v-if="columns.visible('operatingSystem')"
          prop="operatingSystem"
          label="操作系统"
        />
        <el-table-column
          v-if="columns.visible('operatingVersion')"
          prop="operatingVersion"
          label="系统版本"
        />
        <el-table-column v-if="columns.visible('platBase')" prop="platBase" label="构建基本平台" width="100" />
        <el-table-column
          v-if="columns.visible('database')"
          prop="database"
          label="数据库"
        />
        <el-table-column
          v-if="columns.visible('databaseVersion')"
          prop="databaseVersion"
          label="数据库版本"
        />
        <el-table-column
          v-if="columns.visible('databaseMode')"
          prop="databaseMode"
          label="数据库模式"
        />
        <el-table-column v-if="columns.visible('qtVersion')" prop="qtVersion" label="QT版本" />
        <el-table-column
          v-if="columns.visible('developmentTool')"
          prop="developmentTool"
          label="开发工具"
        />
        <el-table-column v-if="columns.visible('startTime')" prop="startTime" label="开始时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('endTime')" prop="endTime" label="结束时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          v-permission="['admin','shipEnvBase:edit','shipEnvBase:del']"
          label="操作"
          width="150px"
          align="center"
        >
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudShipEnvBase from '@/api/shipEnvBase'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '舰艇环境信息', url: 'api/shipEnvBase', sort: 'id,desc', crudMethod: { ...crudShipEnvBase }})
const defaultForm = { id: null, shipNo: null, hardwareEnv: null, inputUnit: null, videoBus: null, conferenceTable: null, softStruct: null, operatingSystem: null, operatingVersion: null, platBase: null, database: null, databaseVersion: null, databaseMode: null, qtVersion: null, developmentTool: null, startTime: null, endTime: null }
export default {
  name: 'ShipEnvBase',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['database_type', 'database_mode'],
  data() {
    return {
      permission: {
        add: ['admin', 'shipEnvBase:add'],
        edit: ['admin', 'shipEnvBase:edit'],
        del: ['admin', 'shipEnvBase:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'id', display_name: 'ID' },
        { key: 'shipNo', display_name: '舷号' },
        { key: 'hardwareEnv', display_name: '硬件' },
        { key: 'inputUnit', display_name: '输入部件' },
        { key: 'videoBus', display_name: '视频总线' },
        { key: 'conferenceTable', display_name: '会商桌' },
        { key: 'softStruct', display_name: '软件架构' },
        { key: 'operatingSystem', display_name: '操作系统' }
      ]
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    }
  }
}
</script>

<style scoped>
</style>
